/*
 * Returns the name of the browser
 */

function whichBrs() {
    var agt=navigator.userAgent.toLowerCase();
    if (agt.indexOf("opera") != -1) return 'Opera';
    if (agt.indexOf("staroffice") != -1) return 'Star Office';
    if (agt.indexOf("webtv") != -1) return 'WebTV';
    if (agt.indexOf("beonex") != -1) return 'Beonex';
    if (agt.indexOf("chimera") != -1) return 'Chimera';
    if (agt.indexOf("netpositive") != -1) return 'NetPositive';
    if (agt.indexOf("phoenix") != -1) return 'Phoenix';
    if (agt.indexOf("firefox") != -1) return 'Firefox';
    if (agt.indexOf("safari") != -1) return 'Safari';
    if (agt.indexOf("skipstone") != -1) return 'SkipStone';
    if (agt.indexOf("msie") != -1) return 'Internet Explorer';
    if (agt.indexOf("netscape") != -1) return 'Netscape';
    if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
    if (agt.indexOf('\/') != -1) {
        if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
            return navigator.userAgent.substr(0,agt.indexOf('\/'));
        }
        else return 'Netscape';
    } else if (agt.indexOf(' ') != -1)
        return navigator.userAgent.substr(0,agt.indexOf(' '));
    else return navigator.userAgent;
}

/**
 * Include a JS File dynmically using JS
 */
function includeJS(script_filename) {
    //One way
    document.write('<' + 'script');
    document.write(' language="javascript"');
    document.write(' type="text/javascript"');
    document.write(' src="' + script_filename + '">');
    document.write('</' + 'script' + '>');

//Second way
//    var headID = document.getElementsByTagName("head")[0];
//    var newScript = document.createElement('script');
//    newScript.type = 'text/javascript';
//    //newScript.onload=scriptLoaded;
//    newScript.src = script_filename;
//    headID.appendChild(newScript);
//alert("Done");
}


//////////////////////////////////////////////////////////////////
//////////////////////	Text Counter	//////////////////////////
//////////////////////////////////////////////////////////////////

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) { // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	}
	// otherwise, update counter
	else { 
		countfield.value = field.value.length;
	}
}

function textCounterById(fieldId, countfield, maxlimit) {
	//alert(document.getElementById(fieldId).value.length);
	//alert(countfield);
	if (document.getElementById(fieldId).value.length > maxlimit) { // if too long...trim it!
		document.getElementById(fieldId).value = document.getElementById(fieldId).value.substring(0, maxlimit);
	}
	// otherwise, update counter
	else { 
		countfield.value = document.getElementById(fieldId).value.length;
	}
}

//////////////////////////////////////////////////////////////////
//////////////////////	Submit Once	//////////////////////////////
//////////////////////////////////////////////////////////////////

var submitcount = 0;
function submitOnce() {
   if (submitcount == 0) {
      submitcount++;
      return true;
   }
   else  {
      //alert("This form has already been submitted.");
      return false;
   }
}


//////////////////////////////////////////////////////////////////
//////////////////////	"zpop" Function	//////////////////////////
//////////////////////////////////////////////////////////////////
var p; 
function zpop(url,id,h,w,mb,tb) { 
p = window.open(url,id,"height="+h+",width="+w+",menubar="+mb+",resizable=yes,toolbar="+tb+",scrollbars=yes"); 
p.window.focus()
} 


//////////////////////////////////////////////////////////////////
/////////	Format Currency (NO DECIMAL POINTS)	//////////////////
//////////////////////////////////////////////////////////////////
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+
			num.substring(num.length-(4*i+3));
			//return (((sign)?'':'-') + '$' + num + '.' + cents);
			return (((sign)?'':'-') + '$' + num);
}

function formatCurrencyDecimal(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+
			num.substring(num.length-(4*i+3));
			return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function writeLang(){
    
    
    if (navigator.browserLanguage.substr(0,2) == "af"){
        document.write('Afrikaans');
    }
    else if (navigator.browserLanguage.substr(0,2) == "ar") {
        if (navigator.browserLanguage.substr(3,2) == "ae")
            document.write('Arabic / United Arab Emirates');
        else if (navigator.browserLanguage.substr(3,2) == "bh")
            document.write('Arabic / Bahrain');
        else if (navigator.browserLanguage.substr(3,2) == "eg")
            document.write('Arabic / Egypt');
        else if (navigator.browserLanguage.substr(3,2) == "dz")
            document.write('Arabic / Algeria');
        else if (navigator.browserLanguage.substr(3,2) == "iq")
            document.write('Arabic / Iraq');
        else if (navigator.browserLanguage.substr(3,2) == "jo")
            document.write('Arabic / Jordan');
        else if (navigator.browserLanguage.substr(3,2) == "kw")
            document.write('Arabic / Kuwait');
        else if (navigator.browserLanguage.substr(3,2) == "lb")
            document.write('Arabic / Lebanon');
        else if (navigator.browserLanguage.substr(3,2) == "ly")
            document.write('Arabic / Libya');
        else if (navigator.browserLanguage.substr(3,2) == "ma")
            document.write('Arabic / Morocco');
        else if (navigator.browserLanguage.substr(3,2) == "om")
            document.write('Arabic / Oman');
        else if (navigator.browserLanguage.substr(3,2) == "qa")
            document.write('Arabic / Qatar');
        else if (navigator.browserLanguage.substr(3,2) == "sa")
            document.write('Arabic / Saudi Arabia');
        else if (navigator.browserLanguage.substr(3,2) == "sy")
            document.write('Arabic / Syria');
        else if (navigator.browserLanguage.substr(3,2) == "tn")
            document.write('Arabic / Tunisia');
        else if (navigator.browserLanguage.substr(3,2) == "ye")
            document.write('Arabic / Yemen');
        else document.write('Arabic');
    }
    else if (navigator.browserLanguage.substr(0,2) == "be")
        document.write('Belarusian');
    else if (navigator.browserLanguage.substr(0,2) == "bg")
        document.write('Bulgarian');
    else if (navigator.browserLanguage.substr(0,2) == "ca")
        document.write('Catalan');
    else if (navigator.browserLanguage.substr(0,2) == "cs")
        document.write('Czech');
    else if (navigator.browserLanguage.substr(0,2) == "da")
        document.write('Danish');
    else if (navigator.browserLanguage.substr(0,2) == "de") {
        if (navigator.browserLanguage.substr(3,2) == "at")
            document.write('German / Austria');
        else if (navigator.browserLanguage.substr(3,2) == "ch")
            document.write('German / Switzerland');
        else if (navigator.browserLanguage.substr(3,2) == "li")
            document.write('German / Liechtenstein');
        else if (navigator.browserLanguage.substr(3,2) == "lu")
            document.write('German / Luxembourg');
        else document.write('German / Germany');
    }
    else if (navigator.browserLanguage.substr(0,2) == "el")
        document.write('Greek / Greece');
    else if (navigator.browserLanguage.substr(0,2) == "en") {
        if (navigator.browserLanguage.substr(3,2) == "us")
            document.write('English / United States');
        else if (navigator.browserLanguage.substr(3,2) == "au")
            document.write('English / Austrailia');
        else if (navigator.browserLanguage.substr(3,2) == "bz")
            document.write('English / Belize');
        else if (navigator.browserLanguage.substr(3,2) == "ca")
            document.write('English / Canada');
        else if (navigator.browserLanguage.substr(3,2) == "gb")
            document.write('English / Great Britain');
        else if (navigator.browserLanguage.substr(3,2) == "ie")
            document.write('English / Ireland');
        else if (navigator.browserLanguage.substr(3,2) == "jm")
            document.write('English / Jamaica');
        else if (navigator.browserLanguage.substr(3,2) == "nz")
            document.write('English / New Zealand');
        else if (navigator.browserLanguage.substr(3,2) == "tt")
            document.write('English / Trinidad');
        else if (navigator.browserLanguage.substr(3,2) == "za")
            document.write('English / South Africa');
        else document.write('English');
    }
    else if (navigator.browserLanguage.substr(0,2) == "es") {
        if (navigator.browserLanguage.substr(3,2) == "ar")
            document.write('Spanish / Argentina');
        else if (navigator.browserLanguage.substr(3,2) == "bo")
            document.write('Spanish / Bolivia');
        else if (navigator.browserLanguage.substr(3,2) == "cl")
            document.write('Spanish / Chile');
        else if (navigator.browserLanguage.substr(3,2) == "co")
            document.write('Spanish / Colombia');
        else if (navigator.browserLanguage.substr(3,2) == "cr")
            document.write('Spanish / Costa Rica');
        else if (navigator.browserLanguage.substr(3,2) == "do")
            document.write('Spanish / Dominican Republic');
        else if (navigator.browserLanguage.substr(3,2) == "ec")
            document.write('Spanish / Ecuador');
        else if (navigator.browserLanguage.substr(3,2) == "gt")
            document.write('Spanish / Guatemala');
        else if (navigator.browserLanguage.substr(3,2) == "hn")
            document.write('Spanish / Honduras');
        else if (navigator.browserLanguage.substr(3,2) == "mx")
            document.write('Spanish / Mexico');
        else if (navigator.browserLanguage.substr(3,2) == "ni")
            document.write('Spanish / Nicaragua');
        else if (navigator.browserLanguage.substr(3,2) == "pa")
            document.write('Spanish / Panama');
        else if (navigator.browserLanguage.substr(3,2) == "pe")
            document.write('Spanish / Peru');
        else if (navigator.browserLanguage.substr(3,2) == "pr")
            document.write('Spanish / Puerto Rico');
        else if (navigator.browserLanguage.substr(3,2) == "py")
            document.write('Spanish / Paraguay');
        else if (navigator.browserLanguage.substr(3,2) == "sv")
            document.write('Spanish / El Salvador');
        else if (navigator.browserLanguage.substr(3,2) == "uy")
            document.write('Spanish / Uruguay');
        else if (navigator.browserLanguage.substr(3,2) == "ve")
            document.write('Spanish / Venezuela');
        else document.write('Spanish / Spain');
    }
    else if (navigator.browserLanguage.substr(0,2) == "et")
        document.write('Estonian');
    else if (navigator.browserLanguage.substr(0,2) == "eu")
        document.write('Basque');
    else if (navigator.browserLanguage.substr(0,2) == "fa")
        document.write('Farsi');
    else if (navigator.browserLanguage.substr(0,2) == "fi")
        document.write('Finnish');
    else if (navigator.browserLanguage.substr(0,2) == "fo")
        document.write('Faeroese');
    else if (navigator.browserLanguage.substr(0,2) == "fr") {
        if (navigator.browserLanguage.substr(3,2) == "be")
            document.write('French / Belgium');
        else if (navigator.browserLanguage.substr(3,2) == "ca")
            document.write('French / Canada');
        else if (navigator.browserLanguage.substr(3,2) == "ch")
            document.write('French / Switzerland');
        else if (navigator.browserLanguage.substr(3,2) == "ca")
            document.write('French / Luxembourg');
        else document.write('French / France');
    }
    else if (navigator.browserLanguage.substr(0,2) == "gd") {
        if (navigator.browserLanguage.substr(3,2) == "ie")
            document.write('Gaelic / Ireland');
        else document.write('Gaelic / Scotland');
    }
    else if (navigator.browserLanguage.substr(0,2) == "he")
        document.write('Hebrew');
    else if (navigator.browserLanguage.substr(0,2) == "hi")
        document.write('Hindi');
    else if (navigator.browserLanguage.substr(0,2) == "hr")
        document.write('Croatian');
    else if (navigator.browserLanguage.substr(0,2) == "hu")
        document.write('Hungarian');
    else if (navigator.browserLanguage.substr(0,2) == "in")
        document.write('Indonesian');
    else if (navigator.browserLanguage.substr(0,2) == "is")
        document.write('Icelandic');
    else if (navigator.browserLanguage.substr(0,2) == "he")
        document.write('Hebrew');
    else if (navigator.browserLanguage.substr(0,2) == "it") {
        if (navigator.browserLanguage.substr(3,2) == "ch")
            document.write('Italian / Switzerland');
        else document.write('Italian / Italy');
    }
    else if (navigator.browserLanguage.substr(0,2) == "ja")
        document.write('Japanese / Japan');
    else if (navigator.browserLanguage.substr(0,2) == "ji")
        document.write('Yiddish');
    else if (navigator.browserLanguage.substr(0,2) == "ko")
        document.write('Korean / Korea');
    else if (navigator.browserLanguage.substr(0,2) == "lt")
        document.write('Lithuanian / Lithuania');
    else if (navigator.browserLanguage.substr(0,2) == "lv")
        document.write('Latvian');
    else if (navigator.browserLanguage.substr(0,2) == "mk")
        document.write('Macedonian / Macedonia');
    else if (navigator.browserLanguage.substr(0,2) == "ms")
        document.write('Malaysian / Malaysia');
    else if (navigator.browserLanguage.substr(0,2) == "mt")
        document.write('Maltese / Malta');
    else if (navigator.browserLanguage.substr(0,2) == "nl") {
        if (navigator.browserLanguage.substr(3,2) == "be")
            document.write('Dutch / Belgium');
        else document.write('Dutch / Netherlands');
    }
    else if (navigator.browserLanguage.substr(0,2) == "pl")
        document.write('Polish / Poland');
    else if (navigator.browserLanguage.substr(0,2) == "pt") {
        if (navigator.browserLanguage.substr(3,2) == "br")
            document.write('Portuguese / Brazil');
        else document.write('Portuguese / Portugual');
    }
    else if (navigator.browserLanguage.substr(0,2) == "rm")
        document.write('Rhaeto-Romanic / Romania');
    else if (navigator.browserLanguage.substr(0,2) == "ro")
        document.write('Romanian / Romania');
    else if (navigator.browserLanguage.substr(0,2) == "ru")
        document.write('Russian / Russia');
    else if (navigator.browserLanguage.substr(0,2) == "sb")
        document.write('Sorbian');
    else if (navigator.browserLanguage.substr(0,2) == "sk")
        document.write('Slovak');
    else if (navigator.browserLanguage.substr(0,2) == "sl")
        document.write('Slovenian');
    else if (navigator.browserLanguage.substr(0,2) == "sq")
        document.write('Albanian / Albania');
    else if (navigator.browserLanguage.substr(0,2) == "sr")
        document.write('Serbian / Serbia');
    else if (navigator.browserLanguage.substr(0,2) == "sv") {
        if (navigator.browserLanguage.substr(3,2) == "fi")
            document.write('Swedish / Finland');
        else document.write('Swedish / Sweden');
    }
    else if (navigator.browserLanguage.substr(0,2) == "sx")
        document.write('Sutu');
    else if (navigator.browserLanguage.substr(0,2) == "sz")
        document.write('Sami');
    else if (navigator.browserLanguage.substr(0,2) == "th")
        document.write('Thai / Thailand');
    else if (navigator.browserLanguage.substr(0,2) == "tn")
        document.write('Tswana');
    else if (navigator.browserLanguage.substr(0,2) == "tr")
        document.write('Turkish / Turkey');
    else if (navigator.browserLanguage.substr(0,2) == "ts")
        document.write('Tsonga');
    else if (navigator.browserLanguage.substr(0,2) == "uk")
        document.write('Ukrainian');
    else if (navigator.browserLanguage.substr(0,2) == "th")
        document.write('Thai / Thailand');
    else if (navigator.browserLanguage.substr(0,2) == "ur")
        document.write('Urdu');
    else if (navigator.browserLanguage.substr(0,2) == "ve")
        document.write('Venda');
    else if (navigator.browserLanguage.substr(0,2) == "vi")
        document.write('Vietnamese / Vietnam');
    else if (navigator.browserLanguage.substr(0,2) == "xh")
        document.write('Xhosa');
    else if (navigator.browserLanguage.substr(0,2) == "zh") {
        if (navigator.browserLanguage.substr(3,2) == "cn")
            document.write('Chinese / China');
        else if (navigator.browserLanguage.substr(3,2) == "hk")
            document.write('Chinese / Hong Kong');
        else if (navigator.browserLanguage.substr(3,2) == "sg")
            document.write('Chinese / Singapore');
        else if (navigator.browserLanguage.substr(3,2) == "tw")
            document.write('Chinese / Taiwan');
        else document.write('Chinese / China');
    }
    else if (navigator.browserLanguage.substr(0,2) == "zu")
        document.write('Zulu');
    else
        document.write('Could not be determined');
}